class Admin::PostsController < ApplicationController
  
  before_filter :is_admin

  layout "posts"

  def show_post_body
    if !params[:id].nil?
      @post = Post.find_by_id(params[:id])
      render :partial => "admin/posts/show_post_body",  :locals => { :post => @post }
    end
  end

  def destroy
    @post = Post.find_by_id(params[:id])
    cat_id = @post.category_id
    parent_id = @post.parent_id
    @post.destroy
    if !(session[:ret_post].nil?)
      session[:ret_post] = nil
    end
    if parent_id.nil?
      redirect_to admin_path
    else
      redirect_to admin_path
    end
  end

  def index
		@posts = Post.find(:all, :conditions => [ "parent_id is ?", nil ])
		@posts = Post.sort_posts( @posts )
  end

  private

  def is_admin
    return true if User.is_admin(session[:user_id])
    session[:denied_path] = request.request_uri
    redirect_to denied_path
  end

end